﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace BasicDataManagement
{
    class AddItemFactory
    {
        private static Dictionary<string, string> dict;

        private AddItemFactory() { }

        public static Window Create(string catType, IOpertation op, string defaultCatName)
        {
            if (dict == null)//内部单例
            {
                //用语映射
                dict = new Dictionary<string, string>();
                dict.Add("套餐", "Combo");
                dict.Add("原料", "Material");
                dict.Add("配菜", "Option");
                dict.Add("单品", "FixedDish");
                dict.Add("自选菜", "ReplaceableDish");
            }

            //工厂
            switch (dict[catType])
            {
                case "Combo":
                    {
                        AddComboItemWindow win = new AddComboItemWindow();
                        win.comboObject = new DataModel.ComboObject("", defaultCatName);
                        win.Cats = new System.Collections.ObjectModel.ObservableCollection<string>(op.LoadComboCategory());
                        win.DefaultCat = defaultCatName;
                        return win;
                    }
                case "Material":
                    {
                        AddMaterialItemWindow win = new AddMaterialItemWindow();
                        win.materialObject = new DataModel.MaterialObject("", defaultCatName);
                        win.Cats = new System.Collections.ObjectModel.ObservableCollection<string>(op.LoadMaterialCategory());
                        win.DefaultCat = defaultCatName;
                        win.state = EditState.Create;
                        return win;
                    }
                case "Option":
                    {
                        AddOptionItemWindow win = new AddOptionItemWindow();
                        win.optionObject = new DataModel.OptionObject("", defaultCatName);
                        win.Cats = new System.Collections.ObjectModel.ObservableCollection<string>(op.LoadOptionCategory());
                        win.DefaultCat = defaultCatName;
                        return win;
                    }
                case "FixedDish":
                    {
                        AddFixedDishItemWindow win = new AddFixedDishItemWindow();
                        win.fixedDishObject = new DataModel.FixedDishObject("", defaultCatName);
                        win.Cats = new System.Collections.ObjectModel.ObservableCollection<string>(op.LoadFixedDishCategory());
                        win.DefaultCat = defaultCatName;
                        return win;
                    }
                case "ReplaceableDish":
                    {
                        AddReplaceableDishItemWindow win = new AddReplaceableDishItemWindow();
                        win.rDishObject = new DataModel.ReplaceableDishObject("", defaultCatName);
                        win.Cats = new System.Collections.ObjectModel.ObservableCollection<string>(op.LoadReplaceableDishCategory());
                        win.DefaultCat = defaultCatName;
                        return win;
                    }
                default:
                    throw new System.Exception("The specified category was not found!");
            }
        }
    }
}
